GitHub Actions
GitHub上でCIする
website
Github Actionsをlocalで実行
.github/workflows/hoge.yml
GitHub Actions extension for VS Code
#WIP
https://www.docswell.com/s/uta8a/KYDW9P-2024-08-22-github-actions-tips#p1
tutorial
GitHub Actions について学ぶ - GitHub Docs
https://kakakakakku.hatenablog.com/entry/2020/07/07/085146
実行単位 ref
workflow
jobの集合
1個1個のまとまったワークフローという感じ
job
stepの集合
1つのjobに対して、1つの runner (GitHub Actions)が用意される
step
actionの集合(?)
もしくはshellのコマンド
ymlでstep書くときのハイフンの有無はなに?
action
最小単位
命令
ちょっとしたものならshellで書く
Dockerと併用すれば任意の言語でactionを作ることができる
https://rhysd.hatenablog.com/entry/2019/11/15/212713
GitHub ActionsにおけるStep/Job/Workflow設計論
用語 ref
event
workflowをtriggerするもの
e.g. push, PR
外部eventもいける #??
https://docs.github.com/ja/rest/reference/repos#create-a-repository-dispatch-event
https://docs.github.com/ja/actions/reference/events-that-trigger-workflows
runner (GitHub Actions)
変数
repository variables
vars.HOGE
repository secret
secrets.HOGE
ビルトインコンテキスト
4. GitHub context (github.*)
code:yaml
${{ github.repository }} # リポジトリ名
${{ github.ref }} # ブランチ/タグ名
${{ github.sha }} # コミットSHA
${{ github.actor }} # アクションを実行したユーザー
${{ github.event_name }} # イベント名
${{ github.workspace }} # ワークスペースディレクトリ
5. Runner context (runner.*)
code:yaml
${{ runner.os }} # OS (Linux, Windows, macOS)
${{ runner.arch }} # アーキテクチャ
${{ runner.temp }} # 一時ディレクトリ
6. Job context (job.*)
code:yaml
${{ job.status }} # ジョブステータス
${{ job.container }} # コンテナ情報
7. Steps context (steps.*)
code:yaml
${{ steps.step-id.outputs.output-name }} # ステップのアウトプット
${{ steps.step-id.conclusion }} # ステップの結果
8. Needs context (needs.*)
code:yaml
${{ needs.job-id.outputs.output-name }} # 依存ジョブのアウトプット
${{ needs.job-id.result }} # 依存ジョブの結果
9. Inputs context (inputs.*)
code:yaml
${{ inputs.input-name }} # ワークフローやアクションの入力値
10. Strategy context (strategy.*)
code:yaml
${{ strategy.fail-fast }} # マトリックス戦略の設定
${{ matrix.version }} # マトリックスの値
環境変数
code:yaml
env:
CUSTOM_VAR: "value"
# ${{ env.CUSTOM_VAR }} で参照
Custom Action
https://zenn.dev/farstep/books/learn-github-actions/viewer/create-custom-actions
https://docs.github.com/ja/actions/sharing-automations/creating-actions/dockerfile-support-for-github-actions
他のActionから再利用できるActionを作る
要は、anthropics/claude-code-actionみたいなのを自前で作って、他リポジトリから呼び出せるようにする
エントリーポイントはaction.yml
例えば、何らかのリポジトリで以下のようなことを書いているとき、
code:yml
steps:
- uses: anthropics/claude-code-action@beta
claude-code-action/action.ymlが呼ばれている
実行のタイミング
別のサービス(e.g. AWS)でホストしているやつへのdeploy後に回す、とかもできるの #??
AWSのhookとかがあればできるかも
それかsleepを使うとか
usecase
一定期間放置されたIssueをCloseする
GitHub Projectsのカラム移動でラベルを付与・削除する
こんなことできるんやmrsekut.icon
決まった時間にテンプレートを利用してIssueを作成する
単体テスト
E2Eテスト
TypeScriptの型エラーをPR上に表示する ref
Github Actionsでdeploy時にLighthouse計測をする
https://knowledge.sakura.ad.jp/23478/#:~:text=GitHub%20Actionsでできること,を実行する機能だ。
https://tech.pepabo.com/2021/03/03/ec_efficiency_with_github_actions/
https://blog.cybozu.io/entry/2022/12/19/183000
GitHubのPR上に表示されるcheckboxにcheckを付けるとdeployする
価格
About billing for GitHub Actions - GitHub Docs
基本的に無料
planごとにper monthで実行できる時間が変わる
e.g. proなら2000min per month
これを超えた場合は実行できなくなるだけ
勝手に追加課金されたりはしない
macOSを選択するとLinuxの10倍かかる
AWSでhost runner作る
https://dev.classmethod.jp/articles/hosted-runner-on-ec2/
github上ではなく、AWS上で実行するので金がかからない
Action例
https://github.com/marketplace?type=actions
actions/checkout
https://github.com/actions/checkout
なんでcheckoutする必要があるの?
actions/upload-artifact
setup-node
https://github.com/actions/setup-node
v2が出てる
https://rhysd.hatenablog.com/entry/2019/11/11/131505
sleep
https://github.com/marketplace/actions/wait-sleep
oven-sh/setup-bun
https://github.com/oven-sh/setup-bun
memo
default branchに入っていなくても、on:pushになっていれば.github/workflows/hoge.ymlを入れたcommitをpushすれば動く
『GitHub Actions 実践入門』
https://www.kaizenprogrammer.com/entry/2019/10/15/071636
https://tech.medpeer.co.jp/entry/2021/06/24/100000
https://speakerdeck.com/oracle4engineer/get-started-github-actions?slide=29
https://github.com/actions/github-script
https://eh-career.com/engineerhub/entry/2022/05/20/093000
https://kdotdev.com/kdotdev/github-actions?utm_source=pocket_saves
安く使う
Github Actionsでcacheする